package com.ibm.crl.monitor.service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ibm.crl.monitor.client.GraphiteClient;

@Path("/")
public class MetricsResource {
	@Path("/search")
	@GET
	public String metric_search(@QueryParam("from")String from, 
			@QueryParam("until")String until,
			@QueryParam("metric")String metric,
			@QueryParam("format")String format) throws IOException, JSONException{
		System.out.println(from+until+metric+format);
		
		Map<String, String>  map = new HashMap<String, String>();
		map.put("from", from);
		map.put("until", until);
		map.put("format", format);
		map.put("metric", metric);
		
		JSONArray ja = GraphiteClient.fetchRequest(map);
		
		return ja.toString();
	}

	@GET
	public String greet(){
		return "hello";
	}
}
